<? include("../init.php") ?>
<?
  //if ($_POST['submit'] == 1) { // XAMPP Error : Notice: Undefined index: submit 
  if (isset($_POST['submit'])) {

    $password = $_POST['password'];
    $cpassword = $_POST['cpassword'];

    if($password == "" || $cpassword == ""){
      alert("ท่านไม่ได้กรอกรหัสผ่าน กรุณาลองอีกครั้ง");
    }else{
      if ($password != $cpassword) {
        alert('ท่านกรอกรหัสผ่านไม่ตรงกัน');
      }else{
        $db->query("UPDATE user SET password = '$password' WHERE username = '".$_SESSION['username']."'");
        alert("เปลี่ยนรหัสผ่านเรียบร้อย");
      }
    }
  }

?>
<? include('../header.php'); ?>
<? include('../menu.php'); ?>
<? include('submenu.php'); ?>

<div id = "body">

  <form action="password.php" method="post" class = "form"">
    <input type = "hidden" value = "1" name = "submit">
    <div class = 'field'><label></label><h2><?_l('change password')?></h2></div>
    <div class = 'field'><label><?_l('password')?> : </label><input type = "text" class = "input" name = "password"></div>
    <div class = 'field'><label><?_l('re-enter password')?> : </label><input type = "text" class = "input" name = "cpassword"></div>
    <div class = 'field'><label></label>
      <input type = "submit" value = "<?_l('change')?>" class = "btn">
      <input onclick = "javascript:history.back(1)" type = "button" value="<?_l('cancel')?>" class = "btn" />
    </div>
  </form>

</div>

<style>
  .form label{
    width:120px;
  }
</style>
<? include "../footer.php" ?>